<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>【Forest】基于Forest的http客户端框架对接第三方 | ChenWeiHui's Blog</title><meta name="author" content="cwh"><meta name="copyright" content="cwh"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="ForestForest 是一个开源的 Java HTTP 客户端框架，它能够将 HTTP 的所有请求信息（包括 URL、Header 以及 Body 等信息）绑定到您自定义的 Interface 方法上，能够通过调用本地接口方法的方式发送 HTTP 请求。 使用 Forest 就像使用类似 Dubbo 那样的 RPC 框架一样，只需要定义接口，调用接口即可，不必关心具体发送 HTTP  请求的细">
<meta property="og:type" content="article">
<meta property="og:title" content="【Forest】基于Forest的http客户端框架对接第三方">
<meta property="og:url" content="https://gitee.com/CWH6/2023/09/27/%E3%80%90Forest%E3%80%91%E5%9F%BA%E4%BA%8EForest%E7%9A%84http%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%A1%86%E6%9E%B6%E5%AF%B9%E6%8E%A5%E7%AC%AC%E4%B8%89%E6%96%B9/index.html">
<meta property="og:site_name" content="ChenWeiHui&#39;s Blog">
<meta property="og:description" content="ForestForest 是一个开源的 Java HTTP 客户端框架，它能够将 HTTP 的所有请求信息（包括 URL、Header 以及 Body 等信息）绑定到您自定义的 Interface 方法上，能够通过调用本地接口方法的方式发送 HTTP 请求。 使用 Forest 就像使用类似 Dubbo 那样的 RPC 框架一样，只需要定义接口，调用接口即可，不必关心具体发送 HTTP  请求的细">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/xhs.png">
<meta property="article:published_time" content="2023-09-27T14:08:20.000Z">
<meta property="article:modified_time" content="2023-10-09T15:39:17.223Z">
<meta property="article:author" content="cwh">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/xhs.png"><link rel="shortcut icon" href="/bk/img/jljy3.png"><link rel="canonical" href="https://gitee.com/CWH6/2023/09/27/%E3%80%90Forest%E3%80%91%E5%9F%BA%E4%BA%8EForest%E7%9A%84http%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%A1%86%E6%9E%B6%E5%AF%B9%E6%8E%A5%E7%AC%AC%E4%B8%89%E6%96%B9/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/bk/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/bk/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '【Forest】基于Forest的http客户端框架对接第三方',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-10-09 23:39:17'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/xhs.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/bk/archives/"><div class="headline">Articles</div><div class="length-num">66</div></a><a href="/bk/tags/"><div class="headline">Tags</div><div class="length-num">33</div></a><a href="/bk/categories/"><div class="headline">Categories</div><div class="length-num">8</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/bk/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/bk/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/bk/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/bk/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/bk/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/bk/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/bk/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/bk/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/bk/img/alone_blue_sky.jpg')"><nav id="nav"><span id="blog-info"><a href="/bk/" title="ChenWeiHui's Blog"><span class="site-name">ChenWeiHui's Blog</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/bk/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/bk/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/bk/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/bk/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/bk/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/bk/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/bk/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/bk/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">【Forest】基于Forest的http客户端框架对接第三方</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2023-09-27T14:08:20.000Z" title="Created 2023-09-27 22:08:20">2023-09-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2023-10-09T15:39:17.223Z" title="Updated 2023-10-09 23:39:17">2023-10-09</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="【Forest】基于Forest的http客户端框架对接第三方"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Forest"><a href="#Forest" class="headerlink" title="Forest"></a>Forest</h1><p><strong>Forest 是一个开源的<code> Java HTTP 客户端框架</code><strong>，</strong>它能够将 HTTP 的所有请求信息（包括 URL、Header 以及 Body 等信息）绑定到您自定义的 Interface 方法上，能够通过调用本地接口方法的方式发送 HTTP 请求</strong>。</p>
<p>使用 Forest 就像使用<code>类似 Dubbo 那样的 RPC 框架一样，只需要定义接口，调用接口即可</code>，不必关心具体发送 HTTP  请求的细节。同时将 HTTP 请求信息与业务代码<code>解耦</code>，方便您统一管理大量 HTTP 的 URL、Header 等信息。而请求的调用方完全不必在意 HTTP 的具体内容，即使该 HTTP 请求信息发生变更，大多数情况也不需要修改调用发送请求的代码</p>
<blockquote>
<p>官方网站：<a href="https://link.juejin.cn/?target=http://forest.dtflyx.com">forest.dtflyx.com</a></p>
<p>Gitee托管仓库：<a href="https://link.juejin.cn/?target=https://gitee.com/dromara/forest">gitee.com/dromara/for…</a></p>
<p>Github托管仓库：<a href="https://link.juejin.cn/?target=https://github.com/dromara/forest">github.com/dromara/for…</a></p>
</blockquote>
<h2 id="引入"><a href="#引入" class="headerlink" title="引入"></a>引入</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.dtflys.forest<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>forest-spring-boot-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.5.32<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h1 id="调用高德地图服务"><a href="#调用高德地图服务" class="headerlink" title="调用高德地图服务"></a>调用高德地图服务</h1><h3 id="声明高德地图的接口"><a href="#声明高德地图的接口" class="headerlink" title="声明高德地图的接口"></a>声明高德地图的接口</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">AmapClient</span> &#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@Get</span>注解代表该方法专做GET请求</span></span><br><span class="line"><span class="comment">     * 在url中的&#123;0&#125;代表引用第一个参数，&#123;1&#125;引用第二个参数</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Get(&quot;http://ditu.amap.com/service/regeo?longitude=&#123;0&#125;&amp;latitude=&#123;1&#125;&quot;)</span></span><br><span class="line">    Map <span class="title function_">getLocation</span><span class="params">(String longitude, String latitude)</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="控制器"><a href="#控制器" class="headerlink" title="控制器"></a>控制器</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Resource</span></span><br><span class="line"><span class="keyword">private</span> AmapClient amapClient;</span><br><span class="line"></span><br><span class="line"><span class="meta">@GetMapping(&quot;forest&quot;)</span></span><br><span class="line"><span class="meta">@ApiOperation(value = &quot;测试forest调用&quot;)</span></span><br><span class="line"><span class="meta">@PreAuthorize(&quot;hasAnyAuthority(&#x27;system:test:list&#x27;)&quot;)</span></span><br><span class="line"><span class="keyword">public</span> Map <span class="title function_">forest</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">Map</span> <span class="variable">result</span> <span class="operator">=</span> amapClient.getLocation(<span class="string">&quot;121.475078&quot;</span>, <span class="string">&quot;31.223577&quot;</span>);</span><br><span class="line">    log.info(<span class="string">&quot;\n======测试forest调用&#123;&#125;=======\n&quot;</span>, result);</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="响应结果"><a href="#响应结果" class="headerlink" title="响应结果"></a>响应结果</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">&quot;data&quot;</span>: &#123;</span><br><span class="line">        <span class="string">&quot;country&quot;</span>: <span class="string">&quot;中国&quot;</span>,</span><br><span class="line">        <span class="string">&quot;code&quot;</span>: <span class="string">&quot;1&quot;</span>,</span><br><span class="line">        <span class="string">&quot;cross_list&quot;</span>: [</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="string">&quot;distance&quot;</span>: <span class="string">&quot;134.533&quot;</span>,</span><br><span class="line">                <span class="string">&quot;level&quot;</span>: <span class="string">&quot;44000, 44000&quot;</span>,</span><br><span class="line">                <span class="string">&quot;latitude&quot;</span>: <span class="string">&quot;31.224198&quot;</span>,</span><br><span class="line">                <span class="string">&quot;crossid&quot;</span>: <span class="string">&quot;021H51F0100123012--021H51F0100123019&quot;</span>,</span><br><span class="line">                <span class="string">&quot;name&quot;</span>: <span class="string">&quot;黄陂南路--金陵中路&quot;</span>,</span><br><span class="line">                <span class="string">&quot;width&quot;</span>: <span class="string">&quot;16, 12&quot;</span>,</span><br><span class="line">                <span class="string">&quot;weight&quot;</span>: <span class="string">&quot;140&quot;</span>,</span><br><span class="line">                <span class="string">&quot;direction&quot;</span>: <span class="string">&quot;SouthEast&quot;</span>,</span><br><span class="line">                <span class="string">&quot;longitude&quot;</span>: <span class="string">&quot;121.473864&quot;</span></span><br><span class="line">            &#125;,</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="string">&quot;distance&quot;</span>: <span class="string">&quot;134.533&quot;</span>,</span><br><span class="line">                <span class="string">&quot;level&quot;</span>: <span class="string">&quot;44000, 44000&quot;</span>,</span><br><span class="line">                <span class="string">&quot;latitude&quot;</span>: <span class="string">&quot;31.224198&quot;</span>,</span><br><span class="line">                <span class="string">&quot;crossid&quot;</span>: <span class="string">&quot;021H51F0100122948--021H51F0100123019&quot;</span>,</span><br><span class="line">                <span class="string">&quot;name&quot;</span>: <span class="string">&quot;金陵西路--金陵中路&quot;</span>,</span><br><span class="line">                <span class="string">&quot;width&quot;</span>: <span class="string">&quot;12, 12&quot;</span>,</span><br><span class="line">                <span class="string">&quot;weight&quot;</span>: <span class="string">&quot;140&quot;</span>,</span><br><span class="line">                <span class="string">&quot;direction&quot;</span>: <span class="string">&quot;SouthEast&quot;</span>,</span><br><span class="line">                <span class="string">&quot;longitude&quot;</span>: <span class="string">&quot;121.473864&quot;</span></span><br><span class="line">            &#125;,</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="string">&quot;distance&quot;</span>: <span class="string">&quot;134.533&quot;</span>,</span><br><span class="line">                <span class="string">&quot;level&quot;</span>: <span class="string">&quot;44000, 44000&quot;</span>,</span><br><span class="line">                <span class="string">&quot;latitude&quot;</span>: <span class="string">&quot;31.224198&quot;</span>,</span><br><span class="line">                <span class="string">&quot;crossid&quot;</span>: <span class="string">&quot;021H51F0100122948--021H51F0100123012&quot;</span>,</span><br><span class="line">                <span class="string">&quot;name&quot;</span>: <span class="string">&quot;金陵西路--黄陂南路&quot;</span>,</span><br><span class="line">                <span class="string">&quot;width&quot;</span>: <span class="string">&quot;12, 16&quot;</span>,</span><br><span class="line">                <span class="string">&quot;weight&quot;</span>: <span class="string">&quot;140&quot;</span>,</span><br><span class="line">                <span class="string">&quot;direction&quot;</span>: <span class="string">&quot;SouthEast&quot;</span>,</span><br><span class="line">                <span class="string">&quot;longitude&quot;</span>: <span class="string">&quot;121.473864&quot;</span></span><br><span class="line">            &#125;</span><br><span class="line">        ],</span><br><span class="line">        <span class="string">&quot;city&quot;</span>: <span class="string">&quot;上海市&quot;</span>,</span><br><span class="line">        <span class="string">&quot;adcode&quot;</span>: <span class="string">&quot;310101&quot;</span>,</span><br><span class="line">        <span class="string">&quot;hn&quot;</span>: <span class="string">&quot;33号&quot;</span>,</span><br><span class="line">        <span class="string">&quot;countrycode&quot;</span>: <span class="string">&quot;CN&quot;</span>,</span><br><span class="line">        <span class="string">&quot;message&quot;</span>: <span class="string">&quot;Successful.&quot;</span>,</span><br><span class="line">        <span class="string">&quot;version&quot;</span>: <span class="string">&quot;1.0&quot;</span>,</span><br><span class="line">        <span class="string">&quot;areacode&quot;</span>: <span class="string">&quot;021&quot;</span>,</span><br><span class="line">        <span class="string">&quot;districtadcode&quot;</span>: <span class="string">&quot;310101&quot;</span>,</span><br><span class="line">        <span class="string">&quot;result&quot;</span>: <span class="string">&quot;true&quot;</span>,</span><br><span class="line">        <span class="string">&quot;cityadcode&quot;</span>: <span class="string">&quot;310000&quot;</span>,</span><br><span class="line">        <span class="string">&quot;province&quot;</span>: <span class="string">&quot;上海市&quot;</span>,</span><br><span class="line">        <span class="string">&quot;pos&quot;</span>: <span class="string">&quot;在香港广场附近, 在嵩山路旁边, 靠近黄陂南路--金陵中路路口&quot;</span>,</span><br><span class="line">        <span class="string">&quot;sea_area&quot;</span>: &#123;</span><br><span class="line">            <span class="string">&quot;adcode&quot;</span>: <span class="string">&quot;&quot;</span>,</span><br><span class="line">            <span class="string">&quot;name&quot;</span>: <span class="string">&quot;&quot;</span></span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="string">&quot;district&quot;</span>: <span class="string">&quot;黄浦区&quot;</span>,</span><br><span class="line">        <span class="string">&quot;road_list&quot;</span>: [</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="string">&quot;distance&quot;</span>: <span class="string">&quot;5&quot;</span>,</span><br><span class="line">                <span class="string">&quot;level&quot;</span>: <span class="string">&quot;4&quot;</span>,</span><br><span class="line">                <span class="string">&quot;latitude&quot;</span>: <span class="string">&quot;31.2235&quot;</span>,</span><br><span class="line">                <span class="string">&quot;name&quot;</span>: <span class="string">&quot;淮海中路&quot;</span>,</span><br><span class="line">                <span class="string">&quot;width&quot;</span>: <span class="string">&quot;12&quot;</span>,</span><br><span class="line">                <span class="string">&quot;roadid&quot;</span>: <span class="string">&quot;021H51F0100122187&quot;</span>,</span><br><span class="line">                <span class="string">&quot;direction&quot;</span>: <span class="string">&quot;North&quot;</span>,</span><br><span class="line">                <span class="string">&quot;longitude&quot;</span>: <span class="string">&quot;121.475&quot;</span></span><br><span class="line">            &#125;,</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="string">&quot;distance&quot;</span>: <span class="string">&quot;26&quot;</span>,</span><br><span class="line">                <span class="string">&quot;level&quot;</span>: <span class="string">&quot;5&quot;</span>,</span><br><span class="line">                <span class="string">&quot;latitude&quot;</span>: <span class="string">&quot;31.2236&quot;</span>,</span><br><span class="line">                <span class="string">&quot;name&quot;</span>: <span class="string">&quot;嵩山路&quot;</span>,</span><br><span class="line">                <span class="string">&quot;width&quot;</span>: <span class="string">&quot;8&quot;</span>,</span><br><span class="line">                <span class="string">&quot;roadid&quot;</span>: <span class="string">&quot;021H51F0100122281&quot;</span>,</span><br><span class="line">                <span class="string">&quot;direction&quot;</span>: <span class="string">&quot;West&quot;</span>,</span><br><span class="line">                <span class="string">&quot;longitude&quot;</span>: <span class="string">&quot;121.475&quot;</span></span><br><span class="line">            &#125;,</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="string">&quot;distance&quot;</span>: <span class="string">&quot;73&quot;</span>,</span><br><span class="line">                <span class="string">&quot;level&quot;</span>: <span class="string">&quot;4&quot;</span>,</span><br><span class="line">                <span class="string">&quot;latitude&quot;</span>: <span class="string">&quot;31.2232&quot;</span>,</span><br><span class="line">                <span class="string">&quot;name&quot;</span>: <span class="string">&quot;黄陂南路&quot;</span>,</span><br><span class="line">                <span class="string">&quot;width&quot;</span>: <span class="string">&quot;16&quot;</span>,</span><br><span class="line">                <span class="string">&quot;roadid&quot;</span>: <span class="string">&quot;021H51F0100123012&quot;</span>,</span><br><span class="line">                <span class="string">&quot;direction&quot;</span>: <span class="string">&quot;NorthEast&quot;</span>,</span><br><span class="line">                <span class="string">&quot;longitude&quot;</span>: <span class="string">&quot;121.474&quot;</span></span><br><span class="line">            &#125;</span><br><span class="line">        ],</span><br><span class="line">        <span class="string">&quot;provinceadcode&quot;</span>: <span class="string">&quot;310000&quot;</span>,</span><br><span class="line">        <span class="string">&quot;tel&quot;</span>: <span class="string">&quot;021&quot;</span>,</span><br><span class="line">        <span class="string">&quot;timestamp&quot;</span>: <span class="string">&quot;1696688748512&quot;</span>,</span><br><span class="line">        <span class="string">&quot;desc&quot;</span>: <span class="string">&quot;上海市,上海市,黄浦区&quot;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="string">&quot;status&quot;</span>: <span class="string">&quot;1&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h1 id="模拟与客户服务对接"><a href="#模拟与客户服务对接" class="headerlink" title="模拟与客户服务对接"></a>模拟与客户服务对接</h1><p>这里假设我们为<code>A系统</code>，客户的系统为<code>B系统</code>，当我们系统都能在<code>公网上正常访问</code>，又假设A系统的资源与B系统的资源是<code>有关联的</code>，我们可以将提供一些可调用的接口（服务）给对方，<strong>为了保证双方系统的数据安全，双方需要协定秘钥算法有效期等规则</strong>（此处忽略）</p>
<blockquote>
<p>例子背景</p>
<p>A系统采用了spring Security 框架做了认证授权, B系统则无任何认证授权</p>
<p>A系统：<a target="_blank" rel="noopener" href="http://localhost:8723/">http://localhost:8723</a></p>
<p>B系统：<a target="_blank" rel="noopener" href="http://localhost:8081/">http://localhost:8081</a></p>
</blockquote>
<h2 id="A系统调用B系统"><a href="#A系统调用B系统" class="headerlink" title="A系统调用B系统"></a>A系统调用B系统</h2><h3 id="B系统服务"><a href="#B系统服务" class="headerlink" title="B系统服务"></a>B系统服务</h3><ul>
<li><p><strong>课程详情</strong> ：<a target="_blank" rel="noopener" href="http://localhost:8081/test/course/detail?courseId=12">http://localhost:8081/test/course/detail?courseId=12</a></p>
</li>
<li><p><strong>课程列表</strong> ：<a target="_blank" rel="noopener" href="http://localhost:8081/test//course/list">http://localhost:8081/test//course/list</a></p>
</li>
</ul>
<h3 id="A系统设置B系统服务"><a href="#A系统设置B系统服务" class="headerlink" title="A系统设置B系统服务"></a>A系统设置B系统服务</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * A系统设置B系统提供的服务</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">TripartiteClient</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// b系统的域名</span></span><br><span class="line">    <span class="type">String</span> <span class="variable">B_DOMAIN_URL</span> <span class="operator">=</span> <span class="string">&quot;http://localhost:8081&quot;</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * b系统的课程接口</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> courseId 课程id</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> res</span></span><br><span class="line"><span class="comment">     * url: http://localhost:8081/test/course/detail?courseId=12</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Get(</span></span><br><span class="line"><span class="meta">        url = B_DOMAIN_URL + &quot;/test/course/detail&quot;</span></span><br><span class="line"><span class="meta">    )</span></span><br><span class="line">    String <span class="title function_">getCourseDetail</span><span class="params">(<span class="meta">@Query(&quot;courseId&quot;)</span> Long courseId)</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * b系统的课程列表接口</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> res</span></span><br><span class="line"><span class="comment">     * url: http://localhost:8081/test//course/list</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Post(</span></span><br><span class="line"><span class="meta">        url = B_DOMAIN_URL + &quot;/test/course/list&quot;</span></span><br><span class="line"><span class="meta">    )</span></span><br><span class="line">    String <span class="title function_">getCourseList</span><span class="params">()</span>;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="A系统调用B系统服务"><a href="#A系统调用B系统服务" class="headerlink" title="A系统调用B系统服务"></a>A系统调用B系统服务</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Resource</span></span><br><span class="line"><span class="keyword">private</span> TripartiteClient tripartiteClient;</span><br><span class="line"></span><br><span class="line"><span class="meta">@GetMapping(&quot;testB&quot;)</span></span><br><span class="line"><span class="meta">@ApiOperation(value = &quot;测试调用b系统&quot;)</span></span><br><span class="line"><span class="meta">@PreAuthorize(&quot;hasAnyAuthority(&#x27;system:test:list&#x27;)&quot;)</span></span><br><span class="line"><span class="keyword">public</span> R&lt;Map&gt; <span class="title function_">testB</span><span class="params">()</span> &#123;</span><br><span class="line">     log.info(<span class="string">&quot;方法已经执行了&quot;</span>);</span><br><span class="line">     <span class="type">String</span> <span class="variable">courseDetail</span> <span class="operator">=</span> tripartiteClient.getCourseDetail((<span class="type">long</span>) <span class="number">12</span>);</span><br><span class="line">     log.info(<span class="string">&quot;courseDetail===&gt;&quot;</span> + courseDetail);</span><br><span class="line">     <span class="type">String</span> <span class="variable">courseList</span> <span class="operator">=</span> tripartiteClient.getCourseList();</span><br><span class="line">     log.info(<span class="string">&quot;courseList===&gt;&quot;</span> + courseList);</span><br><span class="line">        <span class="keyword">return</span> RUtils.newResponse(MapBoost.createMapWithValues(</span><br><span class="line">                <span class="string">&quot;courseDetail&quot;</span>, courseDetail,</span><br><span class="line">                <span class="string">&quot;courseList&quot;</span>, courseList</span><br><span class="line">        ));</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h3 id="响应"><a href="#响应" class="headerlink" title="响应"></a>响应</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">&quot;code&quot;</span>: <span class="number">0</span>,</span><br><span class="line">    <span class="string">&quot;message&quot;</span>: <span class="string">&quot;&quot;</span>,</span><br><span class="line">    <span class="string">&quot;data&quot;</span>: &#123;</span><br><span class="line">        <span class="string">&quot;courseList&quot;</span>: <span class="string">&quot;[&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:0&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:1&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:2&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:3&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:4&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:5&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:6&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:7&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:8&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:9&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:10&#125;,&#123;\&quot;id\&quot;:null,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:11&#125;]&quot;</span>,</span><br><span class="line">        <span class="string">&quot;courseDetail&quot;</span>: <span class="string">&quot;&#123;\&quot;id\&quot;:\&quot;12\&quot;,\&quot;name\&quot;:\&quot;123123\&quot;,\&quot;cover\&quot;:\&quot;http://12312313.com/test/abc\&quot;,\&quot;autorId\&quot;:123&#125;&quot;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="B系统调用A系统"><a href="#B系统调用A系统" class="headerlink" title="B系统调用A系统"></a>B系统调用A系统</h2><p>A系统采用了Spring Security框架做认证授权，A系统给B系统提供<code>一个权限合适的账号</code>，B系统在调用A系统的其他资源之前，</p>
<p>通过这个账号去调用A系统认证接口 获取<code>对应的token</code>，并在调用A系统的其他资源时，在请求头携带这个token</p>
<h3 id="A系统服务"><a href="#A系统服务" class="headerlink" title="A系统服务"></a>A系统服务</h3><ul>
<li>权限合适的账号：admin  123</li>
<li>认证接口：<a target="_blank" rel="noopener" href="http://localhost:8724/hw/login/user/login">http://localhost:8724/hw/login/user/login</a></li>
<li>资源接口：<a target="_blank" rel="noopener" href="http://localhost:8724/z-self/api/bill/%7Bid%7D">http://localhost:8724/z-self/api/bill/{id}</a></li>
</ul>
<h3 id="B系统设置A系统服务"><a href="#B系统设置A系统服务" class="headerlink" title="B系统设置A系统服务"></a>B系统设置A系统服务</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * B系统设置A系统提供的服务</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">TripartiteClient</span> &#123;</span><br><span class="line">    <span class="comment">// A系统的域名</span></span><br><span class="line">    <span class="type">String</span> <span class="variable">A_DOMAIN_URL</span> <span class="operator">=</span> <span class="string">&quot;http://localhost:8724&quot;</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * A系统的身份认证接口</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> username A系统提供的用户名</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> password A系统提供的用户密码</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> A系统的token</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Post(url = A_DOMAIN_URL + &quot;/hw/login/user/login&quot;)</span></span><br><span class="line">    String <span class="title function_">getToken</span><span class="params">(<span class="meta">@JSONBody(&quot;username&quot;)</span> String username, <span class="meta">@JSONBody(&quot;password&quot;)</span> String password)</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * a系统的资源业务接口</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> id    账单id</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> token 调用身份认证接口获取/根据a系统文档的（密钥，有效期，算法）等验证生成token</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 资源</span></span><br><span class="line"><span class="comment">     * url: http://localhost:8724/z-self/api/bill/&#123;id&#125;</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Get(</span></span><br><span class="line"><span class="meta">            url = A_DOMAIN_URL + &quot;/z-self/api/bill/&#123;id&#125;&quot;</span></span><br><span class="line"><span class="meta">            ,</span></span><br><span class="line"><span class="meta">            headers = &#123;</span></span><br><span class="line"><span class="meta">                    &quot;token: $&#123;token&#125;&quot;</span></span><br><span class="line"><span class="meta">            &#125;</span></span><br><span class="line"><span class="meta">    )</span></span><br><span class="line">    String <span class="title function_">getBillDetail</span><span class="params">(<span class="meta">@Var(&quot;id&quot;)</span> Long id, <span class="meta">@Var(&quot;token&quot;)</span> String token)</span>;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="B系统调用A系统服务"><a href="#B系统调用A系统服务" class="headerlink" title="B系统调用A系统服务"></a>B系统调用A系统服务</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping(&quot;testA&quot;)</span></span><br><span class="line"><span class="meta">@ApiOperation(value = &quot;测试调用a系统&quot;)</span></span><br><span class="line"><span class="keyword">public</span> Map&lt;String,Object&gt; <span class="title function_">testA</span><span class="params">()</span>  &#123;</span><br><span class="line">   <span class="comment">// 获取A系统token</span></span><br><span class="line">   <span class="type">String</span> <span class="variable">tokenJSONStr</span> <span class="operator">=</span> tripartiteClient.getToken(<span class="string">&quot;admin&quot;</span>, <span class="string">&quot;123&quot;</span>);</span><br><span class="line">   log.info(<span class="string">&quot;tokenJSONStr===&gt;&quot;</span> + tokenJSONStr);</span><br><span class="line">   <span class="type">String</span> <span class="variable">tokenStr</span> <span class="operator">=</span> unpack(tokenJSONStr).get(<span class="string">&quot;token&quot;</span>);</span><br><span class="line">   </span><br><span class="line">   <span class="comment">// 携带token向A系统发送请求 </span></span><br><span class="line">   <span class="type">String</span> <span class="variable">billDetailJSONStr</span> <span class="operator">=</span> tripartiteClient.getBillDetail((<span class="type">long</span>) <span class="number">12</span>, tokenStr);</span><br><span class="line">   log.info(<span class="string">&quot;billDetailJSONStr===&gt;&quot;</span> + billDetailJSONStr);</span><br><span class="line">   Map&lt;String, String&gt; dataMap = unpack(billDetailJSONStr);</span><br><span class="line">   <span class="type">String</span> <span class="variable">unpackJson</span> <span class="operator">=</span> JSONUtil.toJsonStr(dataMap);</span><br><span class="line">   <span class="type">Bill</span> <span class="variable">bill</span> <span class="operator">=</span> JSONUtil.toBean(unpackJson, Bill.class);</span><br><span class="line"></span><br><span class="line">   HashMap&lt;String, Object&gt; resMap = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line">   resMap.put(<span class="string">&quot;token&quot;</span>, tokenStr);</span><br><span class="line">   resMap.put(<span class="string">&quot;billDetail&quot;</span>, bill);</span><br><span class="line">     <span class="keyword">return</span> resMap;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> Map&lt;String,String&gt; <span class="title function_">unpack</span><span class="params">(String resJSONStr)</span> &#123;</span><br><span class="line">      <span class="type">Map</span> <span class="variable">map</span> <span class="operator">=</span> JSONUtil.toBean(resJSONStr, Map.class);</span><br><span class="line">      <span class="keyword">return</span> (Map&lt;String,String&gt;)map.get(<span class="string">&quot;data&quot;</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="响应-1"><a href="#响应-1" class="headerlink" title="响应"></a>响应</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">&quot;billDetail&quot;</span>: &#123;</span><br><span class="line">        <span class="string">&quot;id&quot;</span>: <span class="number">12</span>,</span><br><span class="line">        <span class="string">&quot;userId&quot;</span>: <span class="literal">null</span>,</span><br><span class="line">        <span class="string">&quot;categoryId&quot;</span>: <span class="number">5</span>,</span><br><span class="line">        <span class="string">&quot;amount&quot;</span>: <span class="number">5</span>,</span><br><span class="line">        <span class="string">&quot;remark&quot;</span>: <span class="string">&quot;æµ‹è¯•&quot;</span>,</span><br><span class="line">        <span class="string">&quot;dateTime&quot;</span>: <span class="string">&quot;2023-09-12&quot;</span>,</span><br><span class="line">        <span class="string">&quot;createTime&quot;</span>: <span class="string">&quot;2023-09-22T08:53:10.000+0000&quot;</span>,</span><br><span class="line">        <span class="string">&quot;updateTime&quot;</span>: <span class="literal">null</span>,</span><br><span class="line">        <span class="string">&quot;isDelete&quot;</span>: <span class="number">0</span>,</span><br><span class="line">        <span class="string">&quot;pcategoryId&quot;</span>: <span class="literal">null</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="string">&quot;token&quot;</span>: <span class="string">&quot;eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiZXhwIjoxNjk2OTUxNzI0LCJpYXQiOjE2OTY4NjUzMjR9.ec6TcjeNp0YMPqgLiRuKpPCN_fsgnya6Z0KnFM6nIx5QF_DRPBT6Z5FEMWPdEbGcIeg8D9bHFcWUW1NVZHlWog&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="https://gitee.com/CWH6">cwh</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="https://gitee.com/CWH6/2023/09/27/%E3%80%90Forest%E3%80%91%E5%9F%BA%E4%BA%8EForest%E7%9A%84http%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%A1%86%E6%9E%B6%E5%AF%B9%E6%8E%A5%E7%AC%AC%E4%B8%89%E6%96%B9/">https://gitee.com/CWH6/2023/09/27/%E3%80%90Forest%E3%80%91%E5%9F%BA%E4%BA%8EForest%E7%9A%84http%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%A1%86%E6%9E%B6%E5%AF%B9%E6%8E%A5%E7%AC%AC%E4%B8%89%E6%96%B9/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/xhs.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/bk/2023/09/28/%E3%80%90Jmeter%E3%80%91Jmeter%E6%8E%A5%E5%8F%A3%E6%B5%8B%E8%AF%95/" title="【JMeter】JMeter接口测试"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">【JMeter】JMeter接口测试</div></div></a></div><div class="next-post pull-right"><a href="/bk/2023/09/27/%E5%85%B3%E4%BA%8E%E5%A4%9A%E4%B8%AA%E5%85%B3%E9%94%AE%E5%AD%97%E6%9F%A5%E8%AF%A2/" title="关于多个关键字查询"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">关于多个关键字查询</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/xhs.png" onerror="this.onerror=null;this.src='/bk/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">cwh</div><div class="author-info__description">新博客地址：http://cwh6.gitee.io/vuepressv2/</div></div><div class="card-info-data site-data is-center"><a href="/bk/archives/"><div class="headline">Articles</div><div class="length-num">66</div></a><a href="/bk/tags/"><div class="headline">Tags</div><div class="length-num">33</div></a><a href="/bk/categories/"><div class="headline">Categories</div><div class="length-num">8</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="mailto:2747758546@qq.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a><a class="social-icon" href="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/wx_self.jpg" target="_blank" title="wx"><i class="fas fa-qq" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">ありがとう、私の暗い世界の小さな太陽、ありがとう、ずっと温めてくれた</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Forest"><span class="toc-number">1.</span> <span class="toc-text">Forest</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%95%E5%85%A5"><span class="toc-number">1.1.</span> <span class="toc-text">引入</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%B0%83%E7%94%A8%E9%AB%98%E5%BE%B7%E5%9C%B0%E5%9B%BE%E6%9C%8D%E5%8A%A1"><span class="toc-number">2.</span> <span class="toc-text">调用高德地图服务</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A3%B0%E6%98%8E%E9%AB%98%E5%BE%B7%E5%9C%B0%E5%9B%BE%E7%9A%84%E6%8E%A5%E5%8F%A3"><span class="toc-number">2.0.1.</span> <span class="toc-text">声明高德地图的接口</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8E%A7%E5%88%B6%E5%99%A8"><span class="toc-number">2.0.2.</span> <span class="toc-text">控制器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%93%8D%E5%BA%94%E7%BB%93%E6%9E%9C"><span class="toc-number">2.0.3.</span> <span class="toc-text">响应结果</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%A8%A1%E6%8B%9F%E4%B8%8E%E5%AE%A2%E6%88%B7%E6%9C%8D%E5%8A%A1%E5%AF%B9%E6%8E%A5"><span class="toc-number">3.</span> <span class="toc-text">模拟与客户服务对接</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#A%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8B%E7%B3%BB%E7%BB%9F"><span class="toc-number">3.1.</span> <span class="toc-text">A系统调用B系统</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#B%E7%B3%BB%E7%BB%9F%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.1.1.</span> <span class="toc-text">B系统服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#A%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AEB%E7%B3%BB%E7%BB%9F%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.1.2.</span> <span class="toc-text">A系统设置B系统服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#A%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8B%E7%B3%BB%E7%BB%9F%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.1.3.</span> <span class="toc-text">A系统调用B系统服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%93%8D%E5%BA%94"><span class="toc-number">3.1.4.</span> <span class="toc-text">响应</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#B%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8A%E7%B3%BB%E7%BB%9F"><span class="toc-number">3.2.</span> <span class="toc-text">B系统调用A系统</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#A%E7%B3%BB%E7%BB%9F%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.2.1.</span> <span class="toc-text">A系统服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#B%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AEA%E7%B3%BB%E7%BB%9F%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.2.2.</span> <span class="toc-text">B系统设置A系统服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#B%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8A%E7%B3%BB%E7%BB%9F%E6%9C%8D%E5%8A%A1"><span class="toc-number">3.2.3.</span> <span class="toc-text">B系统调用A系统服务</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%93%8D%E5%BA%94-1"><span class="toc-number">3.2.4.</span> <span class="toc-text">响应</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bk/2024/02/05/SpringIOC%E7%9A%84%E7%90%86%E8%A7%A3/" title="SpringIOC的理解">SpringIOC的理解</a><time datetime="2024-02-05T14:26:55.000Z" title="Created 2024-02-05 22:26:55">2024-02-05</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bk/2024/01/18/%E3%80%90ai%E3%80%91chatgpt%E7%BB%95%E5%BC%80%E6%A3%80%E6%9F%A5%E8%BF%87%E6%BB%A4/" title="【ai】chatgpt绕开检查过滤">【ai】chatgpt绕开检查过滤</a><time datetime="2024-01-18T15:55:53.000Z" title="Created 2024-01-18 23:55:53">2024-01-18</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bk/2024/01/15/%E3%80%90ai%E6%A8%A1%E5%9E%8B%E3%80%91%E5%88%A4%E6%96%AD%E8%AF%AD%E5%8F%A5%E7%9A%84%E7%A7%AF%E6%9E%81%E6%80%A7%E4%B8%8E%E6%B6%88%E6%9E%81%E6%80%A7/" title="【ai模型】判断语句的积极性与消极性">【ai模型】判断语句的积极性与消极性</a><time datetime="2024-01-15T13:10:14.000Z" title="Created 2024-01-15 21:10:14">2024-01-15</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bk/2023/12/21/%E3%80%90%E5%8C%BA%E5%9D%97%E9%93%BE%E3%80%91%E4%BB%A5%E5%A4%AA%E5%9D%8A%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6/" title="【区块链】以太坊智能合约">【区块链】以太坊智能合约</a><time datetime="2023-12-21T13:36:30.000Z" title="Created 2023-12-21 21:36:30">2023-12-21</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bk/2023/12/21/%E3%80%90Activiti7%E3%80%91%E5%B7%A5%E4%BD%9C%E6%B5%81%E4%BD%BF%E7%94%A8/" title="【Activiti7】工作流使用">【Activiti7】工作流使用</a><time datetime="2023-12-21T13:21:01.000Z" title="Created 2023-12-21 21:21:01">2023-12-21</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By cwh</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/bk/js/utils.js"></script><script src="/bk/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-show-text.min.js" data-mobile="false" data-text="offer" data-fontsize="15px" data-random="false" async="async"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>